<!--
 * @Author: 淹死De鱼5 happyjing5@sina.cn
 * @Date: 2024-03-16 01:53:16
 * @LastEditors: 淹死De鱼5 happyjing5@sina.cn
-->
<!--  -->
<template>
  <el-dialog v-bind="$attrs" title="分润" :visible.sync="visibleComputed" width="750px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="85px">
      <el-form-item label="分润金额" prop="nodeAllAmount">
        <el-input v-model="form.nodeAllAmount" type="text" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="分润比例" prop="nodeRatio">
        <el-input v-model="form.nodeRatio" type="text" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="isLoading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addShareMoney } from '@/api/reward/contact.js'
export default {
  dicts: ['check_task_status'],
  components: {},
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    id: {
      type: String|Number,
      default: ''
    }
  },
  data () {
    return {
      isLoading: false,
      form: {},
      // 表单校验
      rules: {
        nodeAllAmount: [
          { required: true, message: "分润金额不能为空", trigger: "blur" }
        ],
        nodeRatio: [
          { required: true, message: "分润比例不能为空", trigger: "blur" }
        ],
      }
    }
  },
  computed: {
    visibleComputed: {
      get() {
        return this.visible
      },
      set(value) {
        return this.$emit('update:visible', value)
      }
    }
  },
  mounted() {},
  methods: {
    submitForm() {
      const el = this
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (el.isLoading) return
        //  el.isLoading = true
         const postData = {
          postedId: el.id,
          ...el.form
         }
         addShareMoney(postData).then(res => {
          this.$modal.msgSuccess("添加成功");
          this.cancel()
         }).finally(() => {
            el.isLoading = false
          })
        }
      });
    },
    cancel() {
      this.form = {
        nodeAllAmount: '',
        nodeRatio: '',
        remark: ''
      }
      this.$emit('update:visible', false)
      this.$emit('cancelHandle')
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
